const { defineConfig } = require("@vue/cli-service");
const CompressionWebpackPlugin = require("compression-webpack-plugin");

module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap: process.env.NODE_ENV !== "production",
  publicPath:
    process.env.NODE_ENV === "production" ? "/operation-simulation-web/" : "/",
  configureWebpack: {
    plugins: [
      new CompressionWebpackPlugin({
        test: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i, // 匹配需要进行压缩的文件类型
        threshold: 10240, // 文件大小大于等于 10KB 时进行压缩
        minRatio: 0.8, // 压缩比例达到 80% 时才进行压缩
      }),
    ],
  },
  chainWebpack: (config) => {
    config.optimization.splitChunks({
      chunks: "all",
      minSize: 10000, // 调整最小大小阈值
      minChunks: 1,
      automaticNameDelimiter: "~",
      cacheGroups: {
        element: {
          chunks: "all",
          name: "element-ui",
          test: /[\\/]element-ui[\\/]/,
          priority: 10,
        },
      },
    });

    config.plugin("html").tap((args) => {
      args[0].scriptLoading = "blocking";
      return args;
    });
  },
  devServer: {
    hot: true,
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    proxy: {
      "/mock": {
        target: "https://mock.apifox.cn/m1/1280368-0-default",
        changeOrigin: true,
        pathRewrite: {
          "^/mock": "",
        },
      },
      "/service": {
        // target: "http://aitrainer.cmcc-common.test.cmos:20070/aitrainer/common",
        target: "http://10.38.193.152:8082/aitrainer",
        changeOrigin: true,
        pathRewrite: {
          "^/service": "",
        },
      },
    },
  },
});
